from django.contrib import admin

# Register your models here.
from .models import *
from simpleui.admin import AjaxAdmin


from django.utils.formats import date_format
from django.utils.html import format_html

@admin.register(DailyTask)
class DailyTaskAdmin(AjaxAdmin):   
    ordering = ('-create_date', )
    # 要显示的字段
    list_display = ('create_date',"text_data_view")
    # list_display = ('create_date',"text_data","text_data_view")
    # 需要搜索的字段
    search_fields = ('create_date',)


    # 分页显示，一页的数量
    list_per_page = 30


    @admin.display(description='TextField')
    def text_data_view(self, obj):
        max_show_line = 5
        view_text_data = obj.text_data
        if len(split_text_data := obj.text_data.split("\n")) > max_show_line:
            view_text_data = "\n".join(split_text_data[:max_show_line]+[f"(以下数据省略，共{len(split_text_data)}行数据)"])

        return format_html('<pre style="white-space: pre-wrap; font-family: inherit; font-size: inherit; line-height: inherit; min-width: 1024px">{}</pre>', view_text_data)
    


@admin.register(MemberPeople)
class MemberPeopleAdmin(AjaxAdmin):   
    ordering = ('id', )
    # 要显示的字段
    list_display = ('id','name_data',"phone_number")
    # 需要搜索的字段
    search_fields = ('name_data',"phone_number")


    # 分页显示，一页的数量
    list_per_page = 50